﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Shop4Aggies.Data_Access;

namespace Shop4Aggies.Admin
{
    public partial class AddCategory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtCategory.Text))
            {
                ErrorName.Text = "You must specify a category name";
            }
            else
            {
                string newCat = txtCategory.Text;

                using (CommerceEntities db = new CommerceEntities())
                {
                    Category nc = new Category();
                    nc.CategoryName = newCat;

                    db.Categories.AddObject(nc);

                    db.SaveChanges();
                }

                Response.Redirect("~/");
            }
        }
    }
}